package com.wjpeng.wms.web.controller;

import com.wjpeng.wms.domain.Client;
import com.wjpeng.wms.query.QueryObject;
import com.wjpeng.wms.service.IClientService;
import com.wjpeng.wms.util.JSONResult;
import com.wjpeng.wms.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("client")
public class ClientController {
    @Autowired
    private IClientService clientService;

    @RequestMapping("list")
    @RequiredPermission("部门列表")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        model.addAttribute("result",clientService.result(qo));
        return "client/list";
    }

    @RequestMapping("input")
    @RequiredPermission("部门编辑")
    public String input(Model model,Long id){
        if(id != null){
            model.addAttribute("entity",clientService.get(id));
        }
        return "client/input";
    }

    @RequestMapping("delete")
    @ResponseBody
    @RequiredPermission("部门删除")
    public Object delete(Long id){
        if (id != null) {
            clientService.delete(id);
        }
        return new JSONResult();
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    @RequiredPermission("部门新增/更新")
    public Object saveOrUpdate(Client client){
        clientService.saveOrUpdate(client);
        return new JSONResult();
    }




}
